#include<iostream>
using namespace std; 
class Solution {
public:
    int myAtoi(string str) {
        bool fs = 0;
        int i = 0;
        long long ans = 0;
        while (str[i] == ' ')i++;
        if (str[i] == '-')
        {
            fs = 1;
            i++;
        }
        else if(str[i] == '+')
        {
            fs = 0;
            i++;
        }
        while (i < str.length())
        {
            char c = str[i++];
            if (c >= '0' && c <= '9')
            {
                ans *= 10;
                ans += c - '0';
                if (ans != ((int)ans))
                {
                    if (fs)return -2147483648;
                    else return 2147483647;
                }
            }
            else break;
        }
        if (fs)ans = -ans;
        return ans;
    }
};
int main()
{
    Solution s;
    string ss="-123";
    cout << s.myAtoi(ss) << endl;
}